package main

import (
	"fmt"
	"time"
)

func main() {
	/*
		go语言提供了一个select的功能 作用于channel之上，多路复用
		select 会随机公平的选择一个case
		select 的应用场景 1.timeout的超时机制2.判断某个channel是否阻塞

	*/
	//timeout := false
	//go func() {
	//	time.Sleep(time.Second * 2)
	//	timeout = true
	//}()
	//for {
	//	if timeout {
	//		fmt.Println("结束")
	//		break
	//	}
	//	time.Sleep(time.Millisecond * 10)
	//}
	//var timeout chan bool
	timeout := make(chan bool, 1)
	go func() {
		time.Sleep(time.Second * 2)
		timeout <- true
	}()
	timeout2 := make(chan bool, 1)
	go func() {
		time.Sleep(time.Second * 1)
		timeout2 <- true
	}()
	select {
	case <-timeout:
		fmt.Println("超时")
	case <-timeout2:
		fmt.Println("超时1")
	default:
		println("moren")
	}

}
